package com.example.news.controller;

import com.example.news.pojo.form.RoleForm;
import com.example.news.pojo.form.RolePageQuery;
import com.example.news.pojo.vo.RoleVo;
import com.example.news.service.RoleService;
import com.example.news.utils.result.PageResult;
import com.example.news.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
@Tag(name = "3.角色模块")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("/detail/{id}")
    @Operation(summary = "根据id获取角色信息")
    public Result<RoleVo> getRoleByID(@PathVariable Integer id,@RequestHeader String token){
        return roleService.getRoleById(id);
    }

    @GetMapping("/list")
    @Operation(summary = "管理员获取角色分页列表")
    public PageResult<RoleVo> getRoleList(@ParameterObject RolePageQuery rolePageQuery,@RequestHeader String token){
        return roleService.getRoleList(rolePageQuery);
    }

    @PostMapping("/newRole")
    @Operation(summary = "管理员添加角色")
    public  Result<String> addRole(@RequestBody RoleForm roleForm,@RequestHeader String token){
        return roleService.addRole(roleForm);
    }

    @PutMapping("/updateRole")
    @Operation(summary = "修改角色信息")
    public Result<String> updateRole(@RequestBody RoleForm roleForm,@RequestHeader String token){
        return roleService.updateRole(roleForm);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "管理员删除角色")
    public Result<String> deleteRole(@PathVariable Integer id,@RequestHeader String token){
        return roleService.deleteRoleById(id);
    }

}
